package work.mediway.bi.model.vo;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import work.mediway.bi.model.entity.DesignTemplate;
import lombok.Data;

import java.util.Date;
import java.util.List;

/**
 * @author bovane <bovane.ch@gmail.com>
 * @description
 * @create 2023-06-15 14:50
 */
@Data
public class BiDesignTemplateVO {
    /**
     * 模板ID
     */
    private Integer id;

    /**
     * 模版代码
     */
    private String templateCode;

    private String templateName;

    /**
     * 模板名称
     */
    private String templateDesc;

    /**
     * 是否启用
     */
    private Boolean actived;

    /**
     * 创建人
     */
    private String createBy;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新人
     */
    private String updateBy;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 备注
     */
    private String remark;

    /**
     * 原始JSON
     */
    private JSON rawJson;

    /**
     * 模板分组
     */
    private String templateGroup;

    /**
     * 模板图标
     */
    private String icon;

    public static List<BiDesignTemplateVO> convert(List<DesignTemplate> result) {
        List<BiDesignTemplateVO> biDesignTemplateVOS = CollUtil.newArrayList();
        for (DesignTemplate designTemplate : result) {
            BiDesignTemplateVO biDesignTemplateVO = new BiDesignTemplateVO();
            biDesignTemplateVO.setId(designTemplate.getId());
            biDesignTemplateVO.setTemplateCode(designTemplate.getTemplateCode());
            biDesignTemplateVO.setTemplateName(designTemplate.getTemplateName());
            biDesignTemplateVO.setTemplateDesc(designTemplate.getTemplateDesc());
            biDesignTemplateVO.setActived(designTemplate.getActived());
            biDesignTemplateVO.setCreateBy(designTemplate.getCreateBy());
            biDesignTemplateVO.setCreateTime(designTemplate.getCreateTime());
            biDesignTemplateVO.setUpdateBy(biDesignTemplateVO.getUpdateBy());
            biDesignTemplateVO.setUpdateTime(designTemplate.getUpdateTime());
            biDesignTemplateVO.setRemark(designTemplate.getRemark());
            JSON json = JSON.parseObject(designTemplate.getRawJson(), Feature.OrderedField);
            biDesignTemplateVO.setRawJson(json);
            biDesignTemplateVO.setTemplateGroup(designTemplate.getTemplateGroup());
            biDesignTemplateVO.setIcon(designTemplate.getIcon());

            biDesignTemplateVOS.add(biDesignTemplateVO);
        }

        return biDesignTemplateVOS;
    }
}
